﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MiniFox.Security;

namespace MiniFox.Security.Text
{
    /// <summary>
    /// 密码对象抽象类型, 此对象的继承类型可实现通过明文形式的string对象隐式转换得到，例如： MD5Cipher md5pwd = "testpassword";
    /// 同样，密码对象可隐式转换为string对象, 注意：转换为字符串时,密码对象将被转为密文
    /// </summary>
    public class Cipher
    {
        string _plainText;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="plainText"></param>
        public Cipher(string plainText)
        {
            _plainText = plainText;
        }
        /// <summary>
        /// 原始的密码明文字符串
        /// </summary>
        protected internal string PlainText
        {
            get { return _plainText; }
        }
        /// <summary>
        /// 经MD5加密的密码字符串
        /// </summary>
        public virtual string CipherText
        {
            get { return _plainText; }
        }
        /// <summary>
        /// 转换为加密后的密码字符串
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return this.CipherText;
        }
        /// <summary>
        /// 密码对象转为加密字符串
        /// </summary>
        /// <param name="cipher"></param>
        /// <returns></returns>
        public static implicit operator string(Cipher cipher)
        {
            return cipher.ToString();
        }
    }
    
}
